﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Web.UI.Page;

using X.Pager;
using X.Pager.List;
using X.Common;


namespace E.Web.Teacher.classes
{
    public partial class SignUpList : TeacherBasePage
    {
        public IList<ShortClassModel> classList;
        public IList<CourseCategoryModel> cc_list;
        public IList<DictAreaModel> areaList;
        public string courseName = "";
        public string classCode = "";
        public int areaid = -1;
        public string startFromDate;
        public string startToDate;
        public string endFromDate;
        public string endToDate;
        public int categoryid = -1;

        protected override void ShowPage()
        {
            cc_list = GetCourseCategoryList();
            areaList = GetTeacherAreaList(teacherid);

            InitSearchDateTime();
            string act = XRequest.GetString("act");
            classCode = XRequest.GetString("ClassCodeTxt");
            courseName = XRequest.GetString("CourseNameTxt");
            categoryid = XRequest.GetInt("CourseCategorySlt", -1);

            if (areaList.Count == 1)
            {
                areaid = areaList[0].ID;
            }
            else
            {
                areaid = XRequest.GetInt("AreaSlt", -1);
            }

            if (ispost || act == "s")
            {
                //if (!coursename.Equals(""))
                //{
                ClassBLL bll = new ClassBLL();
                ClassModel model = new ClassModel();
                model.ClassCode = classCode;
                model.CourseName = courseName;
                model.CourseCategoryID = categoryid;
                model.AreaID = areaid;
                model.StartFromDate = startFromDate;
                model.StartToDate = startToDate;
                model.EndFromDate = endFromDate;
                model.EndToDate = endToDate;

                if (authority != E.Enum.EnumTeacherAuthority.Admin)
                {
                    model.TeacherID = teacherid;
                }
                else
                {
                    model.TeacherID = -1;
                }

                ClassListModel listModel = new ClassListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));

                listModel = bll.SearchClassByCondition(model, customerPageSize, pageIndex,true);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    classList = listModel.List;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("ClassCodeTxt", classCode);
                    parms.Add("CourseNameTxt", courseName);
                    parms.Add("CourseCategorySlt", categoryid.ToString());
                    parms.Add("AreaSlt", areaid.ToString());
                    parms.Add("StartFromDateTxt", startFromDate);
                    parms.Add("StartToDateTxt", startToDate);
                    parms.Add("EndFromDateTxt", endFromDate);
                    parms.Add("EndToDateTxt", endToDate);
                    mypager = pager.DrawPager("selfpager", parms);
                }
                //}
            }
            if (act == "h")
            {
                string sValue = XRequest.GetString("studentIdArray");
                int courseIDCurr = XRequest.GetInt("courseID", -1);
                string classCodecurr = XRequest.GetString("classCode");
                int classID = XRequest.GetInt("classID", -1);
                int rst = 0;

                ClassBLL bll = new ClassBLL();
                ClassModel model = new ClassModel();
                model.ID = classID;
                model.ClassCode = classCodecurr;
                model.CourseID = courseIDCurr;
                model.TeacherID = teacherid;
                model.StudentArrayId = sValue;
                rst = bll.AddSignUpPublicStudents(model);
            }

        }

        private void InitSearchDateTime()
        {
            try
            {
                if (!XRequest.GetString("StartFromDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("StartFromDateTxt"));
                    startFromDate = XRequest.GetString("StartFromDateTxt");
                }

                if (!XRequest.GetString("StartToDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("StartToDateTxt"));
                    startToDate = XRequest.GetString("StartToDateTxt");
                }

                if (!XRequest.GetString("EndFromDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("EndFromDateTxt"));
                    endFromDate = XRequest.GetString("EndFromDateTxt");
                }

                if (!XRequest.GetString("EndToDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("EndToDateTxt"));
                    endToDate = XRequest.GetString("EndToDateTxt");
                }
            }
            catch (Exception ex)
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}